package org.cresource.basic.util;

import lombok.Data;

/**
 * 成功与否返回对象
 */
@Data
public class AjaxResult {
    private Boolean success = true;
    private String message = "操作成功！";
    private Object resultObj = null;//存储需要返回给前端的扩展值

    public AjaxResult() {
    }

    /**
     * 提供一个返回错误的构造函数
     * @param message
     */
   /* public AjaxResult (String message) {
        this.success = false;
        this.message = message;
    }*/

    /**
     * 对象由自己创建，不交给外部创建
     * @return
     */
    public static AjaxResult me(){
        return new AjaxResult();
    }

    /**
     * 只需要一个返回失败  链式编程
     * @param message
     * @return
     */
    public AjaxResult setMessage(String message) {
        this.success = false;
        this.message = message;
        return this;
    }

    public AjaxResult setResultObj(Object resultObj) {
        this.resultObj = resultObj;
        return this;
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }
}
